package com.cms.recursoshumanos.popup;

import com.cms.recursoshumanos.cache.UserInfoCache;
import com.cms.recursoshumanos.component.base.CustomButtonColored;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.engine.ScreenEngine;
import com.cms.recursoshumanos.handler.BeneficiosAdministrativosScreenHandler;
import com.cms.recursoshumanos.object.BeneficioAdministrativo;

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.VirtualKeyboard;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class BeneficioAdmPopUp extends PopupScreen
{
    /**
     * Creates a new MyScreen object
     */
	//static Utileria tools = new Utileria();
	private CustomButtonColored boton_envio_solicitud,
								boton_cant_beneficio,
								boton_consult_info;
	private BeneficioAdministrativo elBeneficioAdm;

	public BeneficiosAdministrativosScreenHandler handler;
	
	public BeneficioAdmPopUp(BeneficioAdministrativo elBeneficioAdm) 
	{
		super(new VerticalFieldManager( VirtualKeyboard.HIDE_FORCE ) );
		this.elBeneficioAdm = elBeneficioAdm;
		setComponents();
	}
	protected boolean keyChar( char key, int status, int time )
    {
        if( key == Characters.ESCAPE ) {
           close();
           return false;
        }
        else
        {

            return true;
        }
    }
	private void setComponents() 
	{
        LabelField lbl_beneficio = new LabelField("Beneficio: "+elBeneficioAdm.getNombreBeneficioAdministrativo(), 
        												FIELD_HCENTER | DrawStyle.HCENTER);
		LabelField lbl_info_solicitud = new LabelField("Escoger una Opcion", FIELD_HCENTER | DrawStyle.HCENTER);
		
        Field separator = new SeparatorField();
        separator.setMargin( 6, 0, 6, 0 );
        VerticalFieldManager vfm = new VerticalFieldManager(FIELD_HCENTER | DrawStyle.HCENTER | VERTICAL_SCROLL);
        
		boton_envio_solicitud = new CustomButtonColored("Solicitar Planilla",
															ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER | 
															USE_ALL_WIDTH | DrawStyle.HCENTER, 
															Constant.COLOR_BUTTON_FOCUS); 

		boton_envio_solicitud.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			
	   			BeneficiosAdministrativosScreenHandler handler = new BeneficiosAdministrativosScreenHandler();
	   			handler.getPlanillaBeneficiosAdministrativos(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   															UserInfoCache.getInstance().getUsuario().getPassword(), 
																elBeneficioAdm);
				
	       	} 
		}); 
		
		
		boton_cant_beneficio = new CustomButtonColored("Solicitar Cant. Acumulada",
															ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER | 
															USE_ALL_WIDTH | DrawStyle.HCENTER , 
															Constant.COLOR_BUTTON_FOCUS); 

		
		boton_cant_beneficio.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			
	   			BeneficiosAdministrativosScreenHandler handler = new BeneficiosAdministrativosScreenHandler();
	   			handler.getAcumBeneficio(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   															UserInfoCache.getInstance().getUsuario().getPassword(), 
																elBeneficioAdm);
				
	       	} 
		}); 
        
        boton_consult_info = new CustomButtonColored("Informacion General",
        												ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER | 
        												USE_ALL_WIDTH | DrawStyle.HCENTER ,
        												Constant.COLOR_BUTTON_FOCUS); 

        boton_consult_info.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ScreenEngine.getInstance().goPantallaInfoBeneficioAdm(elBeneficioAdm);
	       	} 
		});
        
        add(lbl_beneficio);
        add(lbl_info_solicitud);
        add(separator);
       
        vfm.add( boton_envio_solicitud );
        if (elBeneficioAdm.getIdBeneficioAdministrativo() == 1)
        {
            vfm.add( boton_cant_beneficio );
        }
        vfm.add( boton_consult_info );
        add(vfm);
        			
	}
	
	
}
